import static java.lang.Thread.sleep;

public class ThreadTest {
    public static void main(String[] args) throws InterruptedException {
        Object objectA = new Object();
        Object objectB = new Object();
        Thread thread1 = new Thread(() -> {
            synchronized (objectA) {
                System.out.println("A");
                objectA.notify();
            }
        });
        Thread thread2 = new Thread(() -> {
            synchronized (objectA) {
                try {
                    objectA.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("B");
                synchronized (objectB) {
                    objectB.notify();
                }
            }
        });
        Thread thread3 = new Thread(() -> {
            synchronized (objectB) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                try {
                    objectB.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("C");
            }
        });
        thread2.start();
        thread3.start();
        Thread.sleep(100);
        thread1.start();
    }
}
